package stu.kurs.security;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.appserv.security.ProgrammaticLogin;

@WebServlet(name = "LogoutServlet", urlPatterns = {"/logout"})
public class LogoutServlet extends HttpServlet {

	private static final long serialVersionUID = 162827924341767632L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        destroyLogoutBean(request);
		ProgrammaticLogin pl = new ProgrammaticLogin();
        try {
			pl.logout(request, response, true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.sendRedirect("pages/authorization.html");
	}
	
	private void destroyLogoutBean(HttpServletRequest request){
		request.getSession().setAttribute("logoutBean", null);
	}
}
